package org.ihelpuoo.orm.objs;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.ihelpuoo.algorithm.random.GM;
import org.ihelpuoo.algorithm.random.StringGenerator;

public class Mocker
{
	private static int				id	= 1;
	private static StringGenerator	SG	= new StringGenerator(4,10);

	public static Abc createAbc()
	{
		Abc abc = new Abc();
		abc.setId(getId());
		abc.setName(SG.next());
		abc.setAge(GM.gRandom(20,100));
		abc.setCreateTime(Calendar.getInstance());
		return abc;
	}

	private static int getId()
	{
		return id++;
	}

	public static Person createPerson(String name, String comName, String[] things,
			Map<String, String> ps)
	{
		Company c = new Company();
		c.setName(comName);

		Person person = new Person();
		person.setName(name);
		person.setCompany(c);

		if (null != things)
		{
			List<Thing> list = new ArrayList<Thing>(things.length);
			for (int i = 0; i < things.length; i++)
			{
				list.add(new Thing(person,things[i]));
			}
			person.setThings(list);
		}

		if (null != ps)
		{
			Map<String, Property> map = new HashMap<String, Property>();
			Iterator<String> it = ps.keySet().iterator();
			while (it.hasNext())
			{
				String key = it.next();
				Property p = new Property(person,key,ps.get(key));
				map.put(key,p);
			}
			person.setProperties(map);
		}

		return person;
	}

	public static Cat createCat(String name, int age, String comment)
	{
		Cat cat = new Cat();
		cat.setName(name);
		cat.setAge(age);
		cat.setComment(comment);
		cat.setFoods(createFoods());
		return cat;
	}

	public static Food[] createFoods()
	{
		Food[] fs = new Food[3];
		fs[0] = new Food("Fish",300);
		fs[1] = new Food("Meat",500);
		fs[2] = new Food("Vegetable",40);
		return fs;
	}

	public static TwoWordsDescriptor createTwoWords()
	{
		TwoWordsDescriptor tw = new TwoWordsDescriptor();
		tw.setW1(SG.next());
		tw.setW2(SG.next());
		return tw;
	}

	public static ZzhBean createZzhBean()
	{
		ZzhBean zzh = new ZzhBean();
		zzh.setName(SG.next());
		ZzhSubBean sub = new ZzhSubBean();
		//sub.setTele(SG.next());
		zzh.setZzhSub(sub);
		return zzh;
	}

}
